<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="number" onkeydown="keydownfun(this)" id="kuang" placeholder="请输入100以内的数字"><span id="daxie"></span>
    <p style="color:red;" id="p1q"></p>
    <input type="text" placeholder="请按下回车键" onkeydown="keydownfun2(this)" id="hc"><br />
    <textarea id="" cols="30" rows="10" onselect="selectfun()">头发体验服把布局和雇一个刚刚好不</textarea>

    <script>
        function selectfun() {
            console.log(event)
            var a = event.target.selectionEnd
            var b = event.target.selectionStart
            console.log(`选中的下标索引` + b)
            console.log(`选择的长度` + (a - b))

        }

        function keydownfun2(sr) {
            for (var i = 1; i <= 100; i++) {
                console.log(`第${fun(i)}次：你好`)
            }
        }

        function keydownfun(obj) {
            document.getElementById("daxie").innerHTML = fun(obj.value)
        }

        function fun(num) {
            var arr = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十']
            var res = ''
            if (num < 11) {
                res = arr[num]
            } else if (num > 10 && num < 20) {
                res = "十" + arr[num % 10]
            } else if (num % 10 == 0 && num <= 90) {
                res = arr[parseInt(num / 10)] + "十"
            } else if (num > 20 && num < 100) {
                res = arr[parseInt(num / 10)] + "十" + arr[num % 10]
            } else {
                res = '一百'
            }
            return res
        }
    </script>

</body>

</html>